/**
 * 作者:i-am-waste
 */

let v = new Vue({
    el:"#gameAll",
    data:{
        gameList:[],
        pageNum:1,
    },
    created:function (){
        axios.post("/"+this.pageNum).then(function (response){
            v.gameList = response.data
        })
    },
    methods:{
        page(index){
            axios.post("/"+index).then(function (response){
                v.gameList = response.data
                document.documentElement.scrollTop = document.getElementById("gameDW").offsetTop;
            })
        },
        yiru(index){
            this.$refs.imgshow[index].style.boxShadow = "0  45px 45px  -35px rgba(0,0,0,0.9)"
            this.$refs.pact[index].style.color = "#e72727"
            this.$refs.masact[index].style.bottom = "-30px"
        },
        yichu(index){
            this.$refs.imgshow[index].style.boxShadow = ""
            this.$refs.pact[index].style.color = ""
            this.$refs.masact[index].style.bottom = ""
        },
        cookieShow(){
            this.$Notice.success({
                title: '┗|｀O′|┛ 嗷~~',
                desc: '本大爷加载完毕！赶快从我这里白嫖点东西吧！',
                duration: 5
            });
        },
        wxandqq(index){
            let host = window.location.host
            let title = document.getElementById("name"+index).innerText
            let url = "【暮迟的游戏小屋】  "+title+"  "+"http://"+host+"/gameart/"+index;
            this.copyToClipboard(url)
            v.$Message.success({
                content: "复制成功！快去粘贴吧！",
                duration: 3
            });
        },
        // 点击复制到剪贴板函数
        copyToClipboard(content) {
            if (window.clipboardData) {
                window.clipboardData.setData('text', content);
            } else {
                (function (content) {
                    document.oncopy = function (e) {
                        e.clipboardData.setData('text', content);
                        e.preventDefault();
                        document.oncopy = null;
                    }
                })(content);
                document.execCommand('copy');
            }
        },
    },
    mounted(){
        this.cookieShow()
    }
})

let u = new Vue({
    el:"#gamePcAll",
    data:{
        gamePc:[],
    },
    created:function (){
        axios.post("/pc").then(function (response){
            u.gamePc = response.data
        })
    },
    methods:{
        pcyr(index){
            this.$refs.uptime[index].style.bottom = "-30px"
        },
        pcyc(index){
            this.$refs.uptime[index].style.bottom = ""
        }
    }
})

let e = new Vue({
    el:"#gameDlAll",
    data:{
        gameDl:[],
    },
    created:function (){
        axios.post("/dl").then(function (response){
            e.gameDl = response.data
        })
    },
    methods:{
        dlyr(index){
            this.$refs.uptime[index].style.bottom = "-30px"
        },
        dlyc(index){
            this.$refs.uptime[index].style.bottom = ""
        }
    }
})

let l = new Vue({
    el:"#gameLbt",
    data:{
        gameLbt:[],
        currentIndex:0,
        timer:null
    },
    created:function (){
        axios.get("/lbt").then(function (response){
            l.gameLbt = response.data
        })
    },
    methods:{
        startInterval(){
            clearInterval(this.timer)
            this.timer = setInterval(()=>{
                this.currentIndex++
                if (this.currentIndex < this.gameLbt.length){
                    this.$refs.imgmove.style.transition = "transform 0.6s";
                    this.$refs.imgmove.style.transform = "translateX(-" + this.currentIndex + "00%)";
                    // console.log(this.currentIndex)
                }
                if (this.currentIndex === this.gameLbt.length){
                    this.$refs.imgmove.style.transform = "translateX(0)";
                    this.currentIndex = 0
                }
            },4000)
        },
        yirukz(){
            clearInterval(this.timer)
        },
        yichukz(){
            this.startInterval()
        },
        yiru(index){
            this.$refs.imgmove.style.transform = "translateX(-" + (index) + "00%)";
            this.currentIndex = index
            clearInterval(this.timer)
        },
        yichu(){
            this.startInterval()
        },
    },
    mounted(){
        this.startInterval()
    },
    beforeDestroy() {
        clearInterval(this.timer)
    }
})
